package org.example.quartz.task;

import cn.hutool.db.Entity;
import cn.hutool.db.Session;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.example.quartz.service.LogService;
import org.example.quartz.service.OrgService;
import org.example.quartz.service.UtilService;
import org.example.quartz.util.DataSourceUtil;
import org.quartz.*;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Slf4j
@Component
// 再Job被执行结束后，将会更新JobDataMap，这样下次Job执行后悔使用新的值而不是初始值
@PersistJobDataAfterExecution
// 同一时间将只有一个Job实例被执行，为了避免并发问题导致数据紊乱，建议这两个注解一起使用
@DisallowConcurrentExecution
public class SubjectQuartz implements QuartzTaskJob {

    Map<String, Object> gsMap = DataSourceUtil.getGS();
    //全局接口配置
    String IP = (String) gsMap.get("IP");
    String PORT = (String) gsMap.get("PORT");
    String ECC = (String) gsMap.get("ECC");
    String Bearer = (String) gsMap.get("Bearer");

    //日志
    LogService loginfo = SpringUtil.getBean(LogService.class);
    //orgService
    OrgService orgService = SpringUtil.getBean(OrgService.class);
    //orgService
    UtilService utilService = SpringUtil.getBean(UtilService.class);
    /**
     * 科目接口
     * 接口地址：GSCloud文档3.9
     * http://ip:port/api/jg/syncbddata/v1.0/bdsyncinterface/syncKmzd
     *
     **/
    @SneakyThrows
    @Override
    public void execute(JobExecutionContext context) {
        //传入变量 lastTime 最后抓取时间
        //链接BIP数据库，查询出需要同步的数据，根据TS时间进行判断。
        //TS从中间库表获取到最后一次更新时间，根据此时间进行增量查询推送；
        //中间库日志表记录推送日志，成功、失败、返回信息等（备查）
        //中间库记录最后推送数据的时间，根据时间进行下次查询的条件；
        //查询脚本
        String methodName = "SubjectQuartz";
        JdbcTemplate jdbcTemplate = SpringUtil.getBean(JdbcTemplate.class);
        //1、查询时间
        String ts = utilService.getTs(methodName, jdbcTemplate);
        String orgStr = utilService.getGSOrgStr(jdbcTemplate);
        //2、根据时间查询数据集 (停用和删除的过滤掉，暂不考虑，线下处理)
        String selectSQL = "--会计科目 (BD_ACCASOA） \n" +
                "                --会计科目基本信息 (BD_ACCOUNT） \n" +
                "                --辅助核算 (BD_ACCASS） \n" +
                "                --会计辅助核算项目 (BD_ACCASSITEM） \n" +
                "                --科目表 (BD_ACCCHART） \n" +
                "                --实体 (MD_CLASS） \n" +
                "                 \n" +
                "                 \n" +
                "                SELECT \n" +
                "                --会计年度（BIP无年度概念，取当前年度） \n" +
                "                TO_CHAR(SYSDATE,'YYYY') AS YEAR, \n" +
                "                --科目体系编号 \n" +
                "                '01' AS CHARTOFACC, \n" +
                "                --账簿编号 \n" +
                "                ORG.CODE AS LEDGER, \n" +
                "                --会计类型 \n" +
                "                '0' AS ACCOUNTTYPE, \n" +
                "                --核算组织编码 \n" +
                "                ORG.CODE AS ACCORGCODE, \n" +
                "                --父级科目编码 \n" +
                "                A1.CODE AS PARENTCODE, \n" +
                "                --科目属性编号 \n" +
                "                BT.CCODE AS ACCTITLEPROP, \n" +
                "                --科目编号 \n" +
                "                B.CODE AS CODE, \n" +
                "                --科目名称 \n" +
                "                SUBSTR(B.NAME, INSTR(B.NAME, '\\\',-1)+1) AS NAME, \n" +
                "                --全称策略 \n" +
                "                '0' AS FULLNAMEROLE, \n" +
                "                --科目全称 \n" +
                "                B.NAME AS FULLNAME, \n" +
                "                --助记码 \n" +
                "                B.REMCODE AS MNEMONICCODE, \n" +
                "                --来源方式 \n" +
                "                '4' AS SRCTYPE, \n" +
                "                --余额方向 1、借2、贷 \n" +
                "                (CASE WHEN B.BALANORIENT= 0 THEN '1' ELSE '2' END) AS BALANCEDIR, \n" +
                "                --现金科目（0、非现金1、现金2、银行存款3、其他现金及现金等价物） \n" +
                "                B.CASHTYPE AS CASHACCTITLE, \n" +
                "                --是否日记账（1、是0、否） \n" +
                "                '0' AS ISJOURNALENTRY, \n" +
                "                --是否银行账（1、是0、否） \n" +
                "                '0' AS ISBANKBOOK, \n" +
                "                --是否允许账簿在下级增加（1、是0、否） \n" +
                "                '1' AS ISALLOWLEDGERCHILDADD, \n" +
                "                --AUTHLAYER\\t权限级数\\t\\t\\t1 \n" +
                "                '1' AS AUTHLAYER, \n" +
                "                --AUTHFLAG\\t权限标志\\t\\t\\t0 \n" +
                "                '0' AS AUTHFLAG, \n" +
                "                --REMARK\\t备注\\t\\t\\t\\t \n" +
                "                '' AS REMARK, \n" +
                "                --ISDISABLED\\t是否启用\\tSTRING\\t1\\t是\\t1是0否\\t \n" +
                "                (CASE WHEN B.ENABLESTATE= 2 THEN '1' ELSE '0' END) AS ISDISABLED,  \n" +
                "                --TYPEFLAG\\t公有私有标志\\tSTRING\\t1\\t是\\t一级科目传1（公有科目）其他级次科目传 2（账簿科目）\\t \n" +
                "                (CASE WHEN B.ACCLEV = 1 THEN '1' ELSE '2' END) AS TYPEFLAG,  \n" +
                "                --是否辅助核算  辅助核算有任意一项为1，则为1 \n" +
                "                (CASE WHEN FZ.FZSUM IS NOT NULL THEN '1' ELSE '0' END) AS ISASSISTACC,  \n" +
                "                --ISDEPT\\t部门核算\\t\\t1是 0否 \n" +
                "                '0' AS ISDEPT, \n" +
                "                --ISPERSON\\t个人核算\\t\\t1是 0否 \n" +
                "                '0' AS ISPERSON, \n" +
                "                --ISCANDS\\t往来单位核算\\t\\t1是0否 \n" +
                "                '0' AS  ISCANDS, \n" +
                "                --ISCRCY\\t外币核算\\t\\t0:不核算1:单一币种核算2:全币种核算 \n" +
                "                '' AS  ISCRCY, \n" +
                "                --CRCY\\t核算外币编号\\t\\t \n" +
                "                '0' AS CRCY, \n" +
                "                --ISQTY\\t数量核算\\t\\t1是0否 \n" +
                "                '0' AS ISQTY, \n" +
                "                --QTYEX01\\t数量辅助项1\\t \n" +
                "                '' AS QTYEX01, \n" +
                "                --QTYEX02\\t数量辅助项2\\t\\t \n" +
                "                '' AS QTYEX02, \n" +
                "                --QTYEX03\\t数量辅助项3\\t \n" +
                "                '' AS QTYEX03, \n" +
                "                --ISIT\\t内部交易\\t\\t1是0否 \n" +
                "                (CASE WHEN B.INNERINFO='Y'  THEN '1' ELSE '0' END) AS ISIT,  \n" +
                "                --ISITNOTNULL\\t制单时必须录入对方单位\\t\\t1是0否 \n" +
                "                '' AS  ISITNOTNULL, \n" +
                "                --CANDSRANGE\\t对方单位范围\\t0:全部1:内部单位2:外部单位 \n" +
                "                '' AS CANDSRANGE, \n" +
                "                --BIZCTRL\\t业务限制\\t\\t0:手工制单科目1:通用科目2:业务科目 \n" +
                "                '' AS BIZCTRL, \n" +
                "                --ACCBOOKSTYLE\\t账页格式\\t\\t0:不设置1:金额账2:数量金额账3:外币金额账4:数量外币金额账 \n" +
                "                '' AS ACCBOOKSTYLE, \n" +
                "                --ENDPERIODBAL\\t期末结平\\t\\t0:不检查1:月末检查2:季末检查3:年末检查 \n" +
                "                '' AS ENDPERIODBAL, \n" +
                "                --ISTRANSFERBAL\\t结转余额\\t\\t1是0否 \n" +
                "                '' AS ISTRANSFERBAL, \n" +
                "                --ISSAMEASBALDIR\\t制单时必须同向发生\\t\\t1是0否 \n" +
                "                '' AS ISSAMEASBALDIR, \n" +
                "                --ISDEFICITCTRL\\t赤字控制\\t\\t1是0否 \n" +
                "                '' AS ISDEFICITCTRL, \n" +
                "                --ISCANDSBIZNUM\\t往来核算必填业务号\\t\\t1是0否 \n" +
                "                '' AS ISCANDSBIZNUM, \n" +
                "                --ISCC\\t成本中心核算\\t\\t1是0否 \n" +
                "                '' AS ISCC, \n" +
                "                --自定义EXTENDCHAR \n" +
                "                '' AS EXTENDCHAR, \n" +
                "                --自定义ISUSERDEFNITEM \n" +
                "                '' AS ISUSERDEFNITEM, \n" +
                "                --自定义ISREFBIZ \n" +
                "                '' AS ISREFBIZ, \n" +
                "                --自定义EXTENDNUM \n" +
                "                '' AS EXTENDNUM, \n" +
                "                A.TS AS TS, \n" +
                "                A.PK_ACCASOA AS ID \n" +
                "                FROM \n" +
                "                BD_ACCASOA A \n" +
                "                LEFT JOIN \n" +
                "                BD_ACCOUNT B ON A.PK_ACCOUNT = B.PK_ACCOUNT \n" +
                "                LEFT JOIN  \n" +
                "                BD_ACCOUNT A1 ON B.PID = A1.PK_ACCOUNT \n" +
                "                LEFT JOIN  \n" +
                "                BD_ACCTYPE BT ON B.PK_ACCTYPE = BT.PK_ACCTYPE \n" +
                "                LEFT JOIN \n" +
                "                BD_ACCCHART AC ON A.PK_ACCCHART = AC.PK_ACCCHART \n" +
                "                LEFT JOIN  \n" +
                "                ORG_ORGS ORG ON AC.PK_ORG = ORG.PK_ORG \n" +
                "                LEFT JOIN  \n" +
                "                (SELECT  PK_ACCASOA,COUNT(1) AS FZSUM FROM  BD_ACCASS GROUP BY PK_ACCASOA) FZ ON A.PK_ACCASOA = FZ.PK_ACCASOA \n" +
                "\t\t\t\t\t\t\t\tWHERE \n" +
                "\t\t\t\t\t\t\t\tORG.CODE IN ("+orgStr+")\n" +
                "                AND A.TS > '"+ts+"'" +
                "                 ORDER BY \n" +
                "                 B.ACCLEV ASC,A.TS ASC,B.CODE ASC";

        //查询数据，根据数据结果推送给GS浪潮
        Session oracleSession = DataSourceUtil.getOracleSession();
       // System.out.println("科目查询脚本："+selectSQL);
        List<Entity> query = oracleSession.query(selectSQL);
        //拼装数据，推送给浪潮
        if(query.size()>0){
            for (Map<String, Object> gSmap : query) {
                //查询辅助核算项
                String FZSQL = "select \n" +
                        "org.code as orgcode,\n" +
                        "d.code,\n" +
                        "d.name,\n" +
                        "c.code as fzcode,\n" +
                        "c.name as fzname\n" +
                        "from \n" +
                        "BD_ACCASS a\n" +
                        "LEFT JOIN \n" +
                        "bd_accasoa b on a.PK_ACCASOA = b.PK_ACCASOA\n" +
                        "left join \n" +
                        "bd_account d on b.pk_account = d.pk_account\n" +
                        "left join \n" +
                        "BD_ACCASSITEM c on a.pk_entity = c.pk_accassitem\n" +
                        "left join \n" +
                        "bd_accchart ac on a.PK_ACCCHART = ac.PK_ACCCHART\n" +
                        "left join \n" +
                        "org_orgs org on ac.pk_org = org.pk_org\n" +
                        "where \n" +
                        "d.code = '" + gSmap.get("CODE") + "'\n" +
                        "and\n" +
                        "org.code = '" + gSmap.get("ACCORGCODE") + "'";
                List<Entity> fzQuery = oracleSession.query(FZSQL);
                //根据组织编码，查询出账套信息，如果有多个账套，轮询进行处理
                List<Map<String, Object>> yyztCodeMap = orgService.selectZtCode((String) gSmap.get("ACCORGCODE"), jdbcTemplate);
                //账簿轮询
                for (int x = 0; x < yyztCodeMap.size(); x++) {
                    //ztCode
                    String yyztCode = (String) yyztCodeMap.get(x).get("yyztCode");
                    //gsCode
                    String gsztCode = (String) yyztCodeMap.get(x).get("gsztCode");
                    //kmtx
                    String kmtx = (String) yyztCodeMap.get(x).get("kmtx");
                    //取中间库表yy_org_orgs     Gscocde
                    String gsCode = (String) yyztCodeMap.get(x).get("gsCode");
                    //辅助核算处理
                    if (fzQuery.size() > 0) {
                        for (Map<String, Object> fzmap : fzQuery) {
                            //System.out.println(fzmap.get("fzcode") + "：科目辅助核算处理");
                            String fzCode = (String) fzmap.get("fzcode");
                            //判断是否是部门、人员、往来单位，给是否赋值
                            //查询sql
                            String tsSql = "SELECT \n" +
                                    "id,\n" +
                                    "num,\n" +
                                    "doccode,\n" +
                                    "docname,\n" +
                                    "gscode,\n" +
                                    "tablename,\n" +
                                    "tablekey,\n" +
                                    "codekey,\n" +
                                    "namekey,\n" +
                                    "fzpk,\n" +
                                    "freekey,\n" +
                                    "istrue,\n" +
                                    "ts \n" +
                                    "FROM\n" +
                                    "freemap f \n" +
                                    "WHERE\n" +
                                    "f.doccode = '" + fzCode + "'";
                            List<Map<String, Object>> maps = jdbcTemplate.queryForList(tsSql);
                            //根据查询的数据进行判断
                            //是否部门、个人、往来
                            if (maps.size() > 0) {
                                String istrue = (String) maps.get(0).get("istrue");
                                if (istrue.equals("DEPT")) {
                                    gSmap.put("ISDEPT", "1");
                                } else if (istrue.equals("PERSON")) {
                                    gSmap.put("ISPERSON", "1");
                                } else if (istrue.equals("CANDS")) {
                                    gSmap.put("ISCANDS", "1");
                                }
                            } else {
                                System.out.println(fzCode + "：当前数据有误，中间库未维护对应辅助对照项，无法判断，请检查规则表【freemap】");
                            }
                        }
                    } else {
                        System.out.println(gSmap.get("CODE") + "该科目无辅助核算");
                    }
                    //如果是1级科目，则LEDGER、ACCORGCODE 需要置空 TYPEFLAG 为 1  传空
                    if(gSmap.get("TYPEFLAG").equals("1")){
                        gsztCode = "";
                        gsCode = "";
                    }
                    String GsJson = "{\n" +
                            "\"YEAR\":\"" + gSmap.get("YEAR") + "\",\n" +
                            "\"CHARTOFACC\":\"" + kmtx + "\",\n" +
                            "\"LEDGER\":\"" + gsztCode + "\",\n" +
                            "\"ACCOUNTTYPE\":\"" + gSmap.get("ACCOUNTTYPE") + "\",\n" +
                            "\"ACCORGCODE\":\"" + gsCode + "\",\n" +
                            "\"PARENTCODE\":\"" + gSmap.get("PARENTCODE") + "\",\n" +
                            "\"ACCTITLEPROP\":\"" + gSmap.get("ACCTITLEPROP") + "\",\n" +
                            "\"CODE\":\"" + gSmap.get("CODE") + "\",\n" +
                            "\"NAME\":\"" + gSmap.get("NAME") + "\",\n" +
                            "\"FULLNAMEROLE\":\"" + gSmap.get("FULLNAMEROLE") + "\",\n" +
                           // "\"FULLNAME\":\"" + gSmap.get("FULLNAME") + "\",\n" +
                            "\"FULLNAME\":\"\",\n" +
                            "\"MNEMONICCODE\":\"" + gSmap.get("MNEMONICCODE") + "\",\n" +
                            "\"SRCTYPE\":\"" + gSmap.get("SRCTYPE") + "\",\n" +
                            "\"BALANCEDIR\":\"" + gSmap.get("BALANCEDIR") + "\",\n" +
                            "\"CASHACCTITLE\":\"" + gSmap.get("CASHACCTITLE") + "\",\n" +
                            "\"ISJOURNALENTRY\":\"" + gSmap.get("ISJOURNALENTRY") + "\",\n" +
                            "\"ISBANKBOOK\":\"" + gSmap.get("ISBANKBOOK") + "\",\n" +
                            "\"ISALLOWLEDGERCHILDADD\":\"" + gSmap.get("ISALLOWLEDGERCHILDADD") + "\",\n" +
                            "\"AUTHLAYER\":\"" + gSmap.get("AUTHLAYER") + "\",\n" +
                            "\"AUTHFLAG\":\"" + gSmap.get("AUTHFLAG") + "\",\n" +
                            "\"REMARK\":\"" + gSmap.get("REMARK") + "\",\n" +
                            "\"ISDISABLED\":\"" + gSmap.get("ISDISABLED") + "\",\n" +
                            "\"TYPEFLAG\":\"" + gSmap.get("TYPEFLAG") + "\",\n" +
//                            "\"EXTENDCHAR01\":\"" + gSmap.get("EXTENDCHAR") + "\",\n" +
//                            "\"EXTENDCHAR02\":\"" + gSmap.get("EXTENDCHAR") + "\",\n" +
//                            "\"EXTENDCHAR03\":\"" + gSmap.get("EXTENDCHAR") + "\",\n" +
//                            "\"EXTENDCHAR04\":\"" + gSmap.get("EXTENDCHAR") + "\",\n" +
//                            "\"EXTENDCHAR05\":\"" + gSmap.get("EXTENDCHAR") + "\",\n" +
//                            "\"EXTENDCHAR06\":\"" + gSmap.get("EXTENDCHAR") + "\",\n" +
//                            "\"EXTENDCHAR07\":\"" + gSmap.get("EXTENDCHAR") + "\",\n" +
//                            "\"EXTENDCHAR08\":\"" + gSmap.get("EXTENDCHAR") + "\",\n" +
//                            "\"EXTENDCHAR09\":\"" + gSmap.get("EXTENDCHAR") + "\",\n" +
//                            "\"EXTENDCHAR10\":\"" + gSmap.get("EXTENDCHAR") + "\",\n" +
//                            "\"EXTENDCHAR11\":\"" + gSmap.get("EXTENDCHAR") + "\",\n" +
//                            "\"EXTENDCHAR12\":\"" + gSmap.get("EXTENDCHAR") + "\",\n" +
//                            "\"EXTENDCHAR13\":\"" + gSmap.get("EXTENDCHAR") + "\",\n" +
//                            "\"EXTENDCHAR14\":\"" + gSmap.get("EXTENDCHAR") + "\",\n" +
//                            "\"EXTENDCHAR15\":\"" + gSmap.get("EXTENDCHAR") + "\",\n" +
//                            "\"EXTENDNUM01\":\"" + gSmap.get("EXTENDNUM") + "\",\n" +
//                            "\"EXTENDNUM02\":\"" + gSmap.get("EXTENDNUM") + "\",\n" +
//                            "\"EXTENDNUM03\":\"" + gSmap.get("EXTENDNUM") + "\",\n" +
//                            "\"EXTENDNUM04\":\"" + gSmap.get("EXTENDNUM") + "\",\n" +
//                            "\"EXTENDNUM05\":\"" + gSmap.get("EXTENDNUM") + "\",\n" +
                            "\"ISASSISTACC\":\"" + gSmap.get("ISASSISTACC") + "\",\n" +
                            "\"ISDEPT\":\"" + gSmap.get("ISDEPT") + "\",\n" +
                            "\"ISPERSON\":\"" + gSmap.get("ISPERSON") + "\",\n" +
                            "\"ISCANDS\":\"" + gSmap.get("ISCANDS") + "\",\n" +
                            "\"ISCRCY\":\"" + gSmap.get("ISCRCY") + "\",\n" +
                            "\"CRCY\":\"" + gSmap.get("CRCY") + "\",\n" +
                            "\"ISQTY\":\"" + gSmap.get("ISQTY") + "\",\n" +
                            "\"QTYEX01\":\"" + gSmap.get("QTYEX01") + "\",\n" +
                            "\"QTYEX02\":\"" + gSmap.get("QTYEX02") + "\",\n" +
                            "\"QTYEX03\":\"" + gSmap.get("QTYEX03") + "\",\n" +
                            "\"ISIT\":\"" + gSmap.get("ISIT") + "\",\n" +
                            "\"ISITNOTNULL\":\"" + gSmap.get("ISITNOTNULL") + "\",\n" +
                            "\"CANDSRANGE\":\"" + gSmap.get("CANDSRANGE") + "\",\n" +
                            "\"BIZCTRL\":\"" + gSmap.get("BIZCTRL") + "\",\n" +
                            "\"ACCBOOKSTYLE\":\"" + gSmap.get("ACCBOOKSTYLE") + "\",\n" +
                            "\"ENDPERIODBAL\":\"" + gSmap.get("ENDPERIODBAL") + "\",\n" +
                            "\"ISTRANSFERBAL\":\"" + gSmap.get("ISTRANSFERBAL") + "\",\n" +
                            "\"ISSAMEASBALDIR\":\"" + gSmap.get("ISSAMEASBALDIR") + "\",\n" +
                            "\"ISDEFICITCTRL\":\"" + gSmap.get("ISDEFICITCTRL") + "\",\n" +
                            "\"ISCANDSBIZNUM\":\"" + gSmap.get("ISCANDSBIZNUM") + "\",\n" +
                            "\"ISCC\":\"" + gSmap.get("ISCC") + "\",\n" ;
                    //根据辅助核算判断
                    for(int z = 1; z<100 ; z++){
                        //判断是否有辅助核算
                        String ISUSERDEFNITEMVALUE = "0";
                        if (fzQuery.size() > 0) {
                            for (Map<String, Object> fzmap : fzQuery) {
                               // System.out.println(fzmap.get("fzcode") + "：科目辅助核算处理");
                                String fzCode = (String) fzmap.get("fzcode");
                                //判断是否是部门、人员、往来单位，给是否赋值
                                //查询sql
                                String tsSql = "SELECT \n" +
                                        "id,\n" +
                                        "num,\n" +
                                        "doccode,\n" +
                                        "docname,\n" +
                                        "gscode,\n" +
                                        "tablename,\n" +
                                        "tablekey,\n" +
                                        "codekey,\n" +
                                        "namekey,\n" +
                                        "fzpk,\n" +
                                        "freekey,\n" +
                                        "istrue,\n" +
                                        "ts \n" +
                                        "FROM\n" +
                                        "freemap f \n" +
                                        "WHERE\n" +
                                        "f.doccode = '" + fzCode + "'";
                                List<Map<String, Object>> maps = jdbcTemplate.queryForList(tsSql);
                                //根据查询的数据进行判断
                                //是否自定义辅助
                                if (maps.size() > 0) {
                                    String istrue = (String) maps.get(0).get("istrue");
                                    if (istrue.equals("NO")) {
                                        if(Integer.parseInt((String) maps.get(0).get("gscode")) == z){
                                            ISUSERDEFNITEMVALUE = "1";
                                        }
                                    }
                                } else {
                                    System.out.println(fzCode + "：当前数据有误，中间库未维护对应辅助对照项，无法判断，请检查规则表【freemap】");
                                }
                            }
                        }
                        if(z<10){
                            GsJson += "\"ISUSERDEFNITEM0"+z+"\":\"" + ISUSERDEFNITEMVALUE + "\",\n" ;
                        }else{
                            GsJson += "\"ISUSERDEFNITEM"+z+"\":\"" + ISUSERDEFNITEMVALUE + "\",\n" ;
                        }
                    }
                    //去掉拼接的最后一个字符
                    GsJson = GsJson.substring(0, GsJson.lastIndexOf(','));
                    GsJson +="}";
//                    GsJson +="\"ISREFBIZ01\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ02\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ03\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ04\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ05\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ06\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ07\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ08\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ09\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ10\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ11\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ12\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ13\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ14\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ15\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ16\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ17\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ18\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ19\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ20\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ21\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ22\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ23\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ24\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ25\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ26\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ27\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ28\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ29\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ30\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ31\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ32\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ33\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ34\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ35\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ36\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ37\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ38\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ39\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ40\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ41\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ42\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ43\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ44\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ45\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ46\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ47\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ48\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ49\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ50\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ51\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ52\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ53\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ54\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ55\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ56\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ57\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ58\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ59\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ60\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ61\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ62\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ63\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ64\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ65\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ66\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ67\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ68\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ69\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ70\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ71\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ72\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ73\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ74\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ75\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ76\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ77\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ78\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ79\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ80\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ81\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ82\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ83\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ84\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ85\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ86\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ87\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ88\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ89\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ90\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ91\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ92\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ93\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ94\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ95\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ96\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ97\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ98\":\"" + gSmap.get("ISREFBIZ") + "\",\n" +
//                            "\"ISREFBIZ99\":\"" + gSmap.get("ISREFBIZ") + "\"\n" +
//                            "}";
                    //调用GS接口，推送给GS浪潮，获取返回值;
                    //1、推送用户档案
                    GsJson = GsJson.replace("null","");
                    String gsUrl = "https://" + IP + ":" + PORT + "/api/jg/syncbddata/v1.0/bdsyncinterface/syncKmzd";
                    String returnMSG = HttpRequest.post(gsUrl)
                            .header("Content-Type", "application/json")
                            .header("Accept-Language", "zh-CHS")
                            .header("X-ECC-Current-Tenant", ECC)
                            .header("Authorization", Bearer).timeout(200000)
                            .body(GsJson).execute().body();
                    System.out.println("传入的科目接送【"+GsJson+"】");
                    System.out.println("返回MSG【"+returnMSG+"】");
                    if (!returnMSG.isEmpty()) {
                        String logInsert = "";
                        JSONObject returnObj = JSONObject.parseObject(returnMSG);
                        //成功
                        if (returnObj.get("code").equals("0") ) {
                            int loginsert = loginfo.loginfo(jdbcTemplate, methodName, LocalDateTime.now().toString(), "成功", GsJson, returnMSG, "", (String) gSmap.get("ID"), gsUrl, (String) gSmap.get("TS"));
                            if (loginsert > 0) {
                                System.out.println("日志写入成功！！");
                            } else {
                                System.out.println("日志写入失败！！");
                            }
                            //失败
                        } else if (returnObj.get("code").equals("1") ) {
                            //写入日志表
                            int loginsert = loginfo.loginfo(jdbcTemplate, methodName, LocalDateTime.now().toString(), "失败", GsJson, returnMSG, "",  (String) gSmap.get("ID"), gsUrl, (String) gSmap.get("TS"));
                            if (loginsert > 0) {
                                System.out.println("日志写入成功！！");
                            } else {
                                System.out.println("日志写入失败！！");
                            }
                        }else if(returnObj.get("code")==null && ("").equals(returnObj.get("code"))){
                            //写入日志表
                            int loginsert = loginfo.loginfo(jdbcTemplate, methodName, LocalDateTime.now().toString(), "数据返回异常", GsJson, returnMSG, "",  (String) gSmap.get("ID"), gsUrl, (String) gSmap.get("TS"));
                            if (loginsert > 0) {
                                System.out.println("日志写入成功！！");
                            } else {
                                System.out.println("日志写入失败！！");
                            }
                        }
                    }
                }
            }
        }else{
            System.out.println("暂无新数据推送");
        }

    }


}
